package com.bupt.ilink.mapper;

import com.bupt.ilink.entity.store.Like;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LikeMapper {

    @Insert("INSERT INTO tb_like (user_id, flow_id) VALUES (#{userId}, #{flowId})")
    public void insert(Like like);

    @Delete("DELETE FROM tb_like WHERE user_id = #{userId} AND flow_id = #{flowId}")
    public void deleteLikesByUserId(String userId);

    @Delete("DELETE FROM tb_like WHERE flow_id = #{flowId}")
    public void deleteLikesByFlowId(String flowId);

    @Delete("DELETE FROM tb_like WHERE user_id = #{userId} AND flow_id = #{flowId}")
    public void delete(Like like);

    @Select("SELECT * FROM tb_like WHERE user_id = #{userId}")
    public List<Like> getLikesByUserId(String userId);

    @Select("SELECT * FROM tb_like WHERE flow_id = #{flowId}")
    public List<Like> getLikesByFlowId(String flowId);

    @Select("SELECT count(*) FROM tb_like WHERE user_id = #{userId} AND flow_id = #{flowId}")
    public Boolean exist(Like like);

    @Select("SELECT count(*) FROM tb_like WHERE flow_id = #{flowId}")
    public Integer getLikesCountByFlowId(String flowId);

    @Select("SELECT count(*) FROM tb_like WHERE user_id = #{userId}")
    public Integer getLikesCountByUserId(String userId);

    @Select("SELECT flow_id FROM tb_like WHERE user_id = #{userId}")
    public List<String> getFlowIdsByUserId(String userId);

    @Select("SELECT user_id FROM tb_like WHERE flow_id = #{flowId}")
    public List<String> getUserIdsByFlowId(String flowId);
}
